import { AttrData, IAttrData } from "../../attr/AttrData";
import { AttrType } from "../../attr/AttrType";

/**
 * 战斗角色属性管理器
 */
export class RoleAttrMgr {
    /**基本属性 */
    private _baseAttr: Map<AttrType, number> = new Map();
    /**额外属性 */
    private _extraAttr: Map<AttrType, number> = new Map();

    init(attrDatas: {}) {
        for (let key in attrDatas) {
            let val = this._baseAttr.get(parseInt(key)) || 0;
            this._baseAttr.set(parseInt(key), attrDatas[key] + val);
        }
    }

    getAttr(attrType: AttrType): number {
        let baseVal = this._baseAttr.get(attrType) || 0;
        let extraVal = this._extraAttr.get(attrType) || 0;
        return baseVal + extraVal;
    }


    updateAttr(attrType: AttrType, value: number) {
        let val = this._baseAttr.get(attrType) || 0;
        val = val + value >> 0;
        this._baseAttr.set(attrType, val);
    }
}